package com.creatshare.service.impl;

import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.creatshare.bean.Page;
import com.creatshare.bean.Project;
import com.creatshare.dao.ProjectDao;
import com.creatshare.service.ProjectService;
import com.creatshare.util.ConfigUtils;

@Service
public class ProjectServiceImpl implements ProjectService {
	@Resource
	private ProjectDao projectDao;

	@Override
	public Page getProjectByCategory(int projectcategoryid, int currentPage) {
		int totalRecord = projectDao.getProjectRecordByCategory(projectcategoryid);
		int pageSize = Integer.parseInt(ConfigUtils.getValue("pageSize"));
		List<Project> projectList = null;
		Page page = new Page(currentPage, pageSize, totalRecord);
		try {
			projectList = projectDao.getProjectByCategory(projectcategoryid);
			if (projectList == null || projectList.isEmpty()) {
				page.setRecordList(Collections.emptyList());
			}
			page.setRecordList(projectList);
		} catch (Exception e) {
			e.printStackTrace();
			page.setRecordList(Collections.emptyList());
		}
		return page;
	}
}
